from django.db import models

class ChatUser(models.Model):

    username = models.CharField(default='',max_length=10)
    add_time = models.DateTimeField(auto_now_add=True)
    logins = models.IntegerField(default=1)
    class Meta:
        db_table = 'chat_user'


class UserRelation(models.Model):
    """
    好友列表
    """
    uid = models.IntegerField(default=0)
    obj_uid = models.IntegerField(default=0)
    status = models.IntegerField(default=1)     # 1 已是好友 0 已添加待确认
    last_msg_info = models.JSONField()# {send:1,txt:"",time:"",is_self:0}
    class Meta:
        db_table = 'user_relation'

class Groups(models.Model):
    """"""
    name = models.CharField(default='',max_length=100)
    last_msg_info = models.JSONField()  # {send:1,txt:"",time:""}
    class Meta:
        db_table = 'groups'


class UserGroup(models.Model):
    """"""
    gid = models.IntegerField(default=0)
    uid = models.IntegerField(default=0)
    class Meta:
        db_table = 'user_group'


class ChatMsg(models.Model):
    msg_from = models.IntegerField(default=0)
    msg_to = models.IntegerField(default=0)     # 群的话固定为群ID
    text = models.TextField()
    type = models.IntegerField(default=1)   # 1 好友 2 群
    add_time = models.DateTimeField(auto_now_add=True)
    class Meta:
        db_table = 'chat_msg'

class OnlineUser(models.Model):
    uid = models.IntegerField(default=0)
    channel_name = models.CharField(default='',max_length=200)
    class Meta:
        db_table = 'online_user'